package ssi.tools;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import ssi.tools.Connector;

public class ShowAd {
	public static ArrayList<String> showAd(){
		ArrayList<String> ad = new ArrayList<String>();
		try{
			System.out.println("DZIALAM!");
			Connection connection = new Connector().getConnection();
			Statement statement = connection.createStatement();
			ResultSet result = statement.executeQuery("SELECT * from ad order by id desc limit 1 ");
			System.out.println("DZIALAM2!");
			while (result.next()) {
				System.out.println("DZIALAM3!");
				String title=result.getString("title");
				String ads=result.getString("ad");
				String date=result.getString("date");
				String image = result.getString("images");
				String animalId = result.getString("animalId");
				System.out.println(image);
				ad.add("<h3>"+title+"</h3><img src='images/upload/"+image+"' class='image_frame_430' /><p class='date'>"+date+"</p><p><em><div class='comment more'>"+ads+"</div><br><br>Jestes zainteresowany?</em> <a href='index.jsp?page=animalProfile&id="+animalId+"'>Przejdz do profilu zwierzaka!</a></p><a href='index.jsp?page=showAds' class='more2'>Wiecej ogloszen</a> <br class='cleaner' />");
				
			}
			result.close();
			connection.close();
		}catch(Exception e){
			System.out.println("TUTAJ!");
		}
		return ad;
	}
	
	
	
	public static ArrayList<String> showAds(){
		ArrayList<String> ad = new ArrayList<String>();
		try{
			Connection connection = new Connector().getConnection();
			Statement statement = connection.createStatement();
			ResultSet result = statement.executeQuery("SELECT * from ad order by id desc limit 1,7 ");

			while (result.next()) {
				System.out.println("DZIALAM3!");
				String title=result.getString("title");
				String ads=result.getString("ad");
				String date=result.getString("date");
				String image = result.getString("images");
				String animalId=result.getString("animalId");
				System.out.println(image);
				ad.add("<div class='rp_box'><h3>"+title+"</h3><img src='images/upload/"+image+ "' class='image_frame_100' /><div class='date'>"+date+"</div><p><em><div class='comment more'>"+ads+"</div><br>Jestes zainteresowany?</em> <a href='index.jsp?page=animalProfile&id="+animalId+"'>Przejdz do profilu zwierzaka!</a></p></em></p><div class='cleaner'></div></div>" );
				
			}
			result.close();
			connection.close();
		}catch(Exception e){
			System.out.println("TUTAJ!");
		}
		
		return ad;
	}
}
